package model;

public class BestSolution {
	/*
	 * Active Cooling = 0;
	 * CO2 = 1;
	 * Curtain = 2;
	 * Light = 3;
	 * Sprinkler = 4;
	 * Termostates = 5;
	 * Windows = 6;
	 */
	static boolean[] turnEquipments =new boolean[7];
	public static boolean[] calcBestSolution(House house,Measurement measurements){
		int temp = measurements.getTemp();
		int light = measurements.getLight();
		int cO2 = house.getCurrentCO2();
		int humidity = house.getCurrentHumidity();
		int optTemp = house.getOptTemp();
		int optLight = house.getOptLight();
		int optCO2 = house.getOptCO2();
		int optHumidity = house.getOptHumidity();
		
		int prTemp = Math.abs((int)(((double)optTemp/(double)temp-1)*100));
		int prLight = Math.abs((int)(((double)optLight/(double)light-1)*100));
		int prCO2 = Math.abs((int)(((double)optCO2/(double)cO2-1)*100));
		int prHumd = Math.abs((int)(((double)optHumidity/(double)humidity-1)*100));
		

		
		for(int i = 0; i<turnEquipments.length;i++){
			turnEquipments[i] = false;
		}
		
		//if Temperature i OVER 20% the optimal temp
		if(prTemp>20 && temp>optTemp){
			turnEquipments[6] = true;
			//if Temperature i OVER 40% the optimal temp
			if(prTemp>60 && temp>optTemp){
			turnEquipments[0] = true;
			}
		}
		
		
		if(prTemp>20 && temp<optTemp){
			turnEquipments[5] = true;
		}
		
		
		//if the light is UNDER 20% the optimal light
		if(prLight>20 && light<optLight){
			turnEquipments[3] = true;
		}
		//if the light is OVER 20% the optimal light
		if(prLight>20 && light>optLight){
			turnEquipments[2] = true;
		}
		
		//if there is UNDER 20& CO2 of the optimal CO2
		// and the windows are not open
		if(prCO2<40 && turnEquipments[6]){
			turnEquipments[1] = true;
		}
		
		if(prHumd>20 && humidity<optHumidity){
			turnEquipments[4] = true;
		}else{
			turnEquipments[4] = false;
		}
		
		
//		
//		turnEquipments[0] = true;
//		turnEquipments[1] = false;
//		turnEquipments[2] = true;
//		turnEquipments[3] = false;
//		turnEquipments[4] = true;
//		turnEquipments[5] = false;
//		turnEquipments[6] = true;
		return turnEquipments;
	}
}
